using System;
using System.ComponentModel.DataAnnotations;
using IdeaBlade.EntityModel;
using CoProjectDF.Web.Resources;

namespace CoProjectDF.Models.Login
{

    /// <summary>
    /// Information required for login.
    /// </summary>
    public partial class LoginInfo : VerifiableObject
    {

        [Display(Order = 0, Name = "UserNameLabel", ResourceType = typeof(RegistrationDataResources))]
        [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
        public string UserName
        {
            get { return _userName; }
            set { base.SetProperty("UserName", value, (v) => _userName = v); }
        }

        [Display(Order = 1, Name = "PasswordLabel", ResourceType = typeof(RegistrationDataResources))]
        [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
        public string Password
        {
            get { return (this.PasswordAccessor == null) ? string.Empty : this.PasswordAccessor(); }
            set { base.SetProperty<string>("Password", value, null); }
        }

        [Display(Order = 2, Name = "RememberMeLabel", ResourceType = typeof(ApplicationStrings))]
        public bool RememberMe
        {
            get { return _rememberMe; }
            set { base.SetProperty("RememberMe", value, (v) => _rememberMe = value); }
        }

        internal Func<string> PasswordAccessor { get; set; }

        public ILoginCredential ToLoginCredential()
        {
            return new FormsAuthenticationLoginCredential(UserName, Password, string.Empty, RememberMe);
        }

        private string _userName;
        private bool _rememberMe;

    }
}
